import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @author zj
 * 管理员类
 */
public class Admin {
    private String name;
    private String sid;
    private String username;
    private String password;
    private static Admin instance;

    private Admin(){
        ResultSet rs;
        String sql = "select * from admin";
        try{
            PreparedStatement preSql = DatabaseConnection.getInstance().getCon().prepareStatement(sql);
            rs = preSql.executeQuery();
            if(rs.next()){
                this.name = rs.getString("name");
                this.sid = rs.getString("sid");
                this.username = rs.getString("username");
                this.password = rs.getString("password");
            }
        }catch (Exception e){
            System.out.println(e);
        }
    }

    public static Admin getInstance(){
        if(instance == null) instance = new Admin();
        return instance;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSid() {
        return sid;
    }

    public void setSid(String sid) {
        this.sid = sid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public static void setInstance(Admin instance) {
        Admin.instance = instance;
    }

    public static void removeInstance(){
        instance = null;
    }
}
